package com.example.teacher.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.commonutils.ResultData;
import com.example.teacher.entity.EduCourse;
import com.example.teacher.entity.Teacher;
import com.example.teacher.service.EduCourseService;
import com.example.teacher.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/backstage/teacherFront")
public class TeacherFrontController {
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private EduCourseService courseService;

    @PostMapping(value = "getTeacherFrontList/{page}/{limit}",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultData getTeacherFrontList(@PathVariable long page,@PathVariable long limit){
        Page<Teacher> pageTeacher =new Page<>(page,limit);
        Map<String,Object> map =teacherService.getTeacherFrontList(pageTeacher);
        return ResultData.ok().data(map);
    }

    @GetMapping(value = "getTeacherInfo/{id}",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultData getTeacherAndCourse(@PathVariable String id){
        //根据讲师id查询讲师基本信息
        Teacher teacher =teacherService.getById(id);
        //根据讲师id查询说讲课程
        QueryWrapper<EduCourse> wrapper =new QueryWrapper<>();
        wrapper.eq("teacher_id",id);
        List<EduCourse> courseList = courseService.list(wrapper);
        return ResultData.ok().data("teacher",teacher).data("courseList",courseList);
    }
}
